package model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import database.Database;

public class Roomlist {
	
	/*
	 * REGION private fields
	 */
	ArrayList<String> rooms;
	
	/*
	 * REGION public constructor
	 */
	public Roomlist() {
		load();
	}
	
	/*
	 * REGION public getters
	 */
	public ArrayList<String> getRoomlist() {
		return rooms;
	}
	
	public int getRoomCount() {
		return rooms.size();
	}
	
	/*
	 * REGION public methods
	 */
	public void load() {
		
		// Establish a connection to the database
		Database database = new Database();
		database.connectToDatabase();
		
		try {
			ResultSet rs = database.getRoomlist();
			
			rooms = new ArrayList<String>();
			
			while (rs.next()) {
				int roomID = rs.getInt("ID");
				Room room = new Room(roomID);
				rooms.add(room.getName());
			}
		}
		catch(SQLException e) {
			e.printStackTrace();
		}	
		database.disconnectDatabase();
	}

}
